<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">


            <el-form-item label="扫描人工号" prop="processBy" label-width="88px">
                <el-input v-model="queryParams.processBy" placeholder="请输入扫描人工号" clearable size="small"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="扫描人姓名" prop="processByName" label-width="88px">
                <el-input v-model="queryParams.processByName" placeholder="请输入扫描人姓名" clearable size="small"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="物料PSN" prop="psn" label-width="120px">
                <el-input v-model="queryParams.psn" placeholder="请输入物料PSN" clearable size="small"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="物料09码" prop="barCode" label-width="130px">
                <el-input v-model="queryParams.barCode" placeholder="请输入物料09码" clearable size="small"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="物料SN" prop="sn" label-width="88px">
                <el-input v-model="queryParams.sn" placeholder="请输入物料SN" clearable size="small"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="物料编码" prop="itemCode" label-width="88px">
                <el-input v-model="queryParams.itemCode" placeholder="请输入物料编码" clearable size="small"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="物料供应商代码" prop="mtlVendorCode" label-width="120px">
                <el-input v-model="queryParams.mtlVendorCode" placeholder="请输入物料供应商代码" clearable size="small"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="物料供应商名称" prop="mtlVendorName" label-width="130px">
                <el-input v-model="queryParams.mtlVendorName" placeholder="请输入物料供应商名称" clearable size="small"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="上传标识" prop="uploadFlag" label-width="88px">
                <el-input v-model="queryParams.uploadFlag" placeholder="请输入上传标识" clearable size="small"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="交易时间" prop="processDate" label-width="88px">
                <el-date-picker v-model="dateRange" type="daterange" range-separator="至" start-placeholder="开始日期"
                    end-placeholder="结束日期" value-format="yyyy-MM-dd HH:mm:ss" :default-time="['00:00:00', '23:59:59']">
                </el-date-picker>
            </el-form-item>
            <el-form-item>
                <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="tiList" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="数据源" align="center" prop="dataSource" />
            <el-table-column label="数据源关键字ID" align="center" prop="sourceKeyId" width="120" />
            <el-table-column label="交易时间" align="center" prop="processDate" width="180" />
            <el-table-column label="扫描人工号" align="center" prop="processBy" width="100" />
            <el-table-column label="扫描人姓名" align="center" prop="processByName" width="100" />
            <el-table-column label="数据类型/任务类型/制程阶段" align="center" prop="processStage" width="200" />
            <el-table-column label="阶段代码" align="center" prop="processCode" />
            <el-table-column label="阶段名称" align="center" prop="processName" />
            <el-table-column label="指令号" align="center" prop="instructNo" />
            <el-table-column label="组织id" align="center" prop="orgId" />
            <el-table-column label="任务令" align="center" prop="taskNo" />
            <el-table-column label="产品编码" align="center" prop="barItemCode" />
            <el-table-column label="物料PSN" align="center" prop="psn" />
            <el-table-column label="物料条码" align="center" prop="barcode" />
            <el-table-column label="物料SN" align="center" prop="sn" />
            <el-table-column label="物料编码" align="center" prop="itemCode" />
            <el-table-column label="物料类型" align="center" prop="itemType" />
            <el-table-column label="物料LC" align="center" prop="lotCode" />
            <el-table-column label="物料DC" align="center" prop="dateCode" />
            <el-table-column label="EMS工厂ID" align="center" prop="vendorId" width="120" />
            <el-table-column label="EMS工厂代码" align="center" prop="vendorCode" width="120" />
            <el-table-column label="EMS工厂名称" align="center" prop="vendorName" width="120" />
            <el-table-column label="物料供应商代码" align="center" prop="mtlVendorCode" width="120" />
            <el-table-column label="物料供应商名称" align="center" prop="mtlVendorName" width="120" />
            <el-table-column label="线体" align="center" prop="lineNo" />
            <el-table-column label="工序代码" align="center" prop="workstepCode" />
            <el-table-column label="工序名称" align="center" prop="workstepName" />
            <el-table-column label="数量" align="center" prop="quantity" />
            <el-table-column label="箱LPN(库房）" align="center" prop="boxno" width="120" />
            <el-table-column label="栈板LPN(库房）" align="center" prop="palletNo" width="120" />
            <el-table-column label="创建日期" align="center" prop="createdDate" width="180">
                <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.createdDate, '{y}-{m}-{d}') }}</span>
                </template>
            </el-table-column>
            <el-table-column label="创建人" align="center" prop="createdBy" />
            <el-table-column label="修改日期" align="center" prop="lastUpdatedDate" width="180">
                <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.lastUpdatedDate, '{y}-{m}-{d}') }}</span>
                </template>
            </el-table-column>
            <el-table-column label="修改人" align="center" prop="lastUpdatedBy" />
            <el-table-column label="上传标识" align="center" prop="uploadFlag">
                <template slot-scope="scope">
                    <span>{{
                        scope.row.uploadFlag===0?'待上载':scope.row.uploadFlag===1?'正在上载':scope.row.uploadFlag===2?'上载成功':scope.row.uploadFlag===9?'上载失败':''
                        }}</span>
                </template>
            </el-table-column>
            <el-table-column label="校验标识" align="center" prop="status" />
            <el-table-column label="滚动发料标识" align="center" prop="rollFlag" width="120" />
            <el-table-column label="segment1" align="center" prop="segment1" width="100" />
            <el-table-column label="segment2" align="center" prop="segment2" width="100" />
            <el-table-column label="segment3" align="center" prop="segment3" width="100" />
            <el-table-column label="工厂业务类型代码" align="center" prop="segment40" width="180" />
        </el-table>
        <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
            @pagination="getList" />


    </div>
</template>

<script>
    import { listTi, getTi, delTi, addTi, updateTi, exportTi } from "@/api/ems/wuliaosfsj";

    export default {
        name: "Ti",
        data() {
            return {
                // 遮罩层
                loading: true, dateRange: [],
                // 选中数组
                ids: [],
                // 非单个禁用
                single: true,
                // 非多个禁用
                multiple: true,
                // 显示搜索条件
                showSearch: true,
                // 总条数
                total: 0,
                // EMS厂履历数据表格数据
                tiList: [],
                // 弹出层标题
                title: "",
                // 是否显示弹出层
                open: false,
                // 查询参数
                queryParams: {
                    pageNum: 1,
                    pageSize: 10,
                    processBy: undefined,
                    processByName: undefined,
                    psn: undefined,
                    barCode: undefined,
                    sn: undefined,
                    itemCode: undefined,
                    mtlVendorCode: undefined,
                    mtlVendorName: undefined,
                    uploadFlag: undefined,
                    
                },
                // 表单参数
                form: {},
                // 表单校验
                rules: {
                }
            };
        },
        created() {
            this.getList();
        },
        methods: {
            /** 查询EMS厂履历数据列表 */
            getList() {
                this.loading = true;
                listTi(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
                    this.tiList = response.rows;
                    this.total = response.total;
                    this.loading = false;
                });
            },
            // 取消按钮
            cancel() {
                this.open = false;
                this.reset();
            },
            // 表单重置
            reset() {
                this.form = {};
                this.resetForm("form");
            },
            /** 搜索按钮操作 */
            handleQuery() {
                this.queryParams.pageNum = 1;
                this.getList();
            },
            /** 重置按钮操作 */
            resetQuery() {
                this.dateRange = []
                this.resetForm("queryForm");
                this.handleQuery();
            },
            // 多选框选中数据
            handleSelectionChange(selection) {
                this.ids = selection.map(item => item.interfaceId)
                this.single = selection.length !== 1
                this.multiple = !selection.length
            },
            /** 新增按钮操作 */
            handleAdd() {
                this.reset();
                this.open = true;
                this.title = "添加EMS厂履历数据";
            },
            /** 修改按钮操作 */
            handleUpdate(row) {
                this.reset();
                const interfaceId = row.interfaceId || this.ids
                getTi(interfaceId).then(response => {
                    this.form = response.data;
                    this.open = true;
                    this.title = "修改EMS厂履历数据";
                });
            },
            /** 提交按钮 */
            submitForm() {
                this.$refs["form"].validate(valid => {
                    if (valid) {
                        if (this.form.interfaceId != null) {
                            updateTi(this.form).then(response => {
                                if (response.code === 200) {
                                    this.msgSuccess("修改成功");
                                    this.open = false;
                                    this.getList();
                                }
                            });
                        } else {
                            addTi(this.form).then(response => {
                                if (response.code === 200) {
                                    this.msgSuccess("新增成功");
                                    this.open = false;
                                    this.getList();
                                }
                            });
                        }
                    }
                });
            },
            /** 删除按钮操作 */
            handleDelete(row) {
                const interfaceIds = row.interfaceId || this.ids;
                this.$confirm('是否确认删除EMS厂履历数据编号为"' + interfaceIds + '"的数据项?', "警告", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                }).then(function () {
                    return delTi(interfaceIds);
                }).then(() => {
                    this.getList();
                    this.msgSuccess("删除成功");
                }).catch(function () { });
            },
            /** 导出按钮操作 */
            handleExport() {
                const queryParams = this.queryParams;
                this.$confirm('是否确认导出所有EMS厂履历数据数据项?', "警告", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                }).then(function () {
                    return exportTi(queryParams);
                }).then(response => {
                    this.download(response.msg);
                }).catch(function () { });
            }
        }
    };
</script>